<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of content_change_model
 *
 * @author phamtruong
 */
class content_change_model extends CI_Model {
    //put your code here
    public function get_titel($id_article){
        $query = $this->db->query("SELECT * FROM `article` WHERE `id`='$id_article'");
        return $query->result_array();
    }
    public function get_content($id_article){
        $query = $this->db->query("SELECT * FROM `article_version` WHERE `article_id`='$id_article' 
            and version=(select max(version) from article_version where article_id='$id_article')");
        return $query->result_array();
    }
    public function get_version($id_article){
         $query = $this->db->query("");
         return $query->result_array();
    }
    public function update_article($id_article,$id_used){
        $content=  $this->input->post("content");
        $sql="select max(version) max_version from article_version where article_id=" . $id_article;
        $result = $this->db->query($sql);
        $result_array = $result->result_array();
        $maxVersion = $result_array[0]["max_version"];
        $maxVersion= $maxVersion +1;
        echo $maxVersion;
        $this->db->query("INSERT INTO `article_version`( `content`, `version`, `modified_date`, `article_id`, `contributor_id`) 
            VALUES ('$content','$maxVersion',now(),'$id_article','$id_used')");
//        $content=  $this->input->post("title");
//        $query = $this->db->query("UPDATE `article` SET `title`='$content' WHERE `id`='$id_article'");
    }
}

?>
